import request from "@/utils/request";

//1.获取一级分类列表
//返回值每一项类型
export interface reqCategoryListReturnItemType {
    id: number;
    name: string;
    category1Id?: number;
    category2Id?: number;
}
//返回值类型
export type reqCategoryListReturnType = reqCategoryListReturnItemType[];
//请求一级分类列表
export const requestCategoryList1 = () => {
    return request.get<any, reqCategoryListReturnType>(
        "/admin/product/getCategory1"
    );
};

//2.请求二级分类列表
export const requestCategoryList2 = (category1Id: number) => {
    return request.get<any, reqCategoryListReturnType>(
        `/admin/product/getCategory2/${category1Id}`
    );
};

//3.请求三级分类列表
export const requestCategoryList3 = (category2Id: number) => {
    return request.get<any, reqCategoryListReturnType>(
        `/admin/product/getCategory3/${category2Id}`
    );
};

//4.获取品牌属性信息
//返回值中attrValueList每一项类型
export interface reqAttrReturnAttrValueListItemType {
    id?: number;
    valueName: string;
    attrId: number;
    isEdit?: boolean
}
//返回值每一项类型
export interface reqAttrReturnItemType {
    id?: number;
    attrName: string;
    categoryId: number;
    categoryLevel: number;
    attrValueList: reqAttrReturnAttrValueListItemType[];
}
//返回值类型
export type reqAttrReturnType = reqAttrReturnItemType[]
//请求品牌属性信息
export const requestAttrInfo = (
    category1Id: number,
    category2Id: number,
    category3Id: number
) => {
    return request.get<any, reqAttrReturnType>(
        `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
    );
};

//5.修改或添加属性
export const requestUpdateOrAddAttr = (attrInfo: reqAttrReturnItemType) => {
    return request.post<any,null>('/admin/product/saveAttrInfo',attrInfo)
}

//6.删除属性
export const requestDeleteAttr = (attrId:number) => {
    return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}